package uk.ac.glasgow.demosocs.impl.ui;

import java.util.Set;
import uk.ac.glasgow.clui.CommandDescription;
import uk.ac.glasgow.clui.MinimumArguments;
import uk.ac.glasgow.clui.SystemCommand;
import uk.ac.glasgow.clui.SystemCommandException;
import uk.ac.glasgow.demosocs.Candidate;
import uk.ac.glasgow.demosocs.Election;
import uk.ac.glasgow.demosocs.VotingSystem;

@MinimumArguments(0)
@CommandDescription("List all approved candidates for the current election.")
public class GetCandidatesCommand extends SystemCommand<VotingSystem> {

	public GetCandidatesCommand(VotingSystem facade) {
		super(facade);
	}

	@Override
	public String processCommand(String[] arguments) throws SystemCommandException {

		String guid = facade.getCurrentUserGUID();
		if (guid == null)
			throw new SystemCommandException("No current user set.");

		Election election = facade.getCurrentElection();
		
		
		if (election == null)
			throw new SystemCommandException("No current election set.");
		
		String result = "Approved candidates for election: "+election.getEID()+"\n\n"+
		"Name:\tGUID\n";
		
		Set<Candidate> nominations = election.getCandidates();
		
		for (Candidate e : nominations) 
			result += e.getCandidateForename() + " " +
					e.getCandidateSurname() + "\t" + e.getGUID() + "\n";
			
		return result;
	}

}


